package com.cicadamob.contact.api.service;

import java.util.List;

import com.cicadamob.contact.api.Utils.Data.SharedPreferencesUtil;
import com.gmcc.gz.http_wmmp.utils.ToastUtil_httpwmmp;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

/**
 * 保存系统通讯录联系人到本地数据库
 * @author xmq
 *
 */
public class SyncSysContactAsynTask extends AsyncTask<Void, Void, Boolean> {

	public static final String IS_SYSCONTACT_BACKUP_FIAL = "is_syscontact_backup_fail";
	private Context mContext;
	public SyncSysContactAsynTask(Context context) {
		super();
		this.mContext  = context;
	}
	
	@Override
	protected Boolean doInBackground(Void... params) {
		//已经复制过了
		if(SharedPreferencesUtil.getBoolean(mContext, IS_SYSCONTACT_BACKUP_FIAL)){
			return true;
		}
		List<Contact> contacts = SysContactDao.getAllContacts(mContext);
		boolean result=APPContactDao.saveAllContact(mContext, contacts);
		return result;
	}
	
	@Override
	protected void onPostExecute(Boolean result) {
		super.onPostExecute(result);
		if(result){
			SharedPreferencesUtil.putBoolean(mContext, IS_SYSCONTACT_BACKUP_FIAL, true);
			//Toast.makeText(mContext, "数据库复制完成", Toast.LENGTH_SHORT).show();
		}else{
			SharedPreferencesUtil.putBoolean(mContext, IS_SYSCONTACT_BACKUP_FIAL, false);
		}
		
	}
	

}
